package com.infitecs.eyas.boiler;

import com.infitecs.eyas.boiler.model.SodaParameter;
import com.infitecs.eyas.boiler.service.SodaParameterService;
import com.infitecs.eyas.constant.Constant;
import com.infitecs.eyas.enthalpy.service.EnthalpyService;
import com.infitecs.eyas.result.service.MiddleResultService;
import com.infitecs.eyas.util.DoubleUtil;
import com.infitecs.krill.ajax.response.AjaxResponse;
import com.infitecs.krill.ajax.response.ReturnState;
import fr.expression4j.core.exception.EvalException;
import fr.expression4j.core.exception.ParsingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * User: chenkaiyu
 * Date: 15-5-26
 * Time: 下午7:05
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/boiler/gasogene/")
public class GasogeneController {
    @Autowired
    private SodaParameterService sodaParameterService;
    @Autowired
    private EnthalpyService enthalpyService;
    @Autowired
    private MiddleResultService middleResultService;


    @RequestMapping(value="saveTheValueOfE3",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE3(@RequestParam("E3")double E3,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE3(E3,caseId);
    }

    @RequestMapping(value="saveTheValueOfE4",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE4(@RequestParam("E4")double E4,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE4(E4,caseId);
    }

    @RequestMapping(value="saveTheValueOfE5",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE5(@RequestParam("E5")double E5,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE5(E5,caseId);
    }

    @RequestMapping(value="saveTheValueOfE6",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE6(@RequestParam("E6")double E6,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE6(E6,caseId);
    }

    @RequestMapping(value="saveTheValueOfE7",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE7(@RequestParam("E7")double E7,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE7(E7,caseId);
    }

    @RequestMapping(value="saveTheValueOfE8",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE8(@RequestParam("E8")double E8,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE8(E8,caseId);
    }

    @RequestMapping(value="saveTheValueOfE9",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE9(@RequestParam("E9")double E9,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE9(E9,caseId);
    }

    @RequestMapping(value="saveTheValueOfE13",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE13(@RequestParam("E13")double E13,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE13(E13,caseId);
    }

    @RequestMapping(value="saveTheValueOfE14",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE14(@RequestParam("E14")double E14,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE14(E14,caseId);
    }

    @RequestMapping(value="saveTheValueOfE15",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE15(@RequestParam("E15")double E15,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE15(E15,caseId);
    }

    @RequestMapping(value="saveTheValueOfE16",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE16(@RequestParam("E16")double E16,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE16(E16,caseId);
    }

    @RequestMapping(value="saveTheValueOfE17",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE17(@RequestParam("E17")double E17,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE17(E17,caseId);
    }

    @RequestMapping(value="saveTheValueOfE18",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE18(@RequestParam("E18")double E18,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE18(E18,caseId);
    }

    @RequestMapping(value="saveTheValueOfE19",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE19(@RequestParam("E19")double E19,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE19(E19,caseId);
    }

    @RequestMapping(value="saveTheValueOfE10",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE10(@RequestParam("E10")double E10,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE10(E10,caseId);
    }

    @RequestMapping(value="saveTheValueOfE11",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE11(@RequestParam("E11")double E11,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE11(E11,caseId);
    }

    @RequestMapping(value="saveTheValueOfE12",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE12(@RequestParam("E12")double E12,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE12(E12,caseId);
    }

    @RequestMapping(value="saveTheValueOfE20",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE20(@RequestParam("E20")double E20,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE20(E20,caseId);
    }

    @RequestMapping(value="saveTheValueOfE21",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE21(@RequestParam("E21")double E21,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE21(E21,caseId);
    }

    @RequestMapping(value="saveTheValueOfE22",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE22(@RequestParam("E22")double E22,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE22(E22,caseId);
    }

    @RequestMapping(value="saveTheValueOfE23",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE23(@RequestParam("E23")double E23,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE23(E23,caseId);
    }

    @RequestMapping(value="saveTheValueOfE24",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE24(@RequestParam("E24")double E24,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE24(E24,caseId);
    }

    @RequestMapping(value="saveTheValueOfE25",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE25(@RequestParam("E25")double E25,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE25(E25,caseId);
    }

    @RequestMapping(value="saveTheValueOfE26",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE26(@RequestParam("E26")double E26,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE26(E26,caseId);
    }

    @RequestMapping(value="saveTheValueOfE27",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE27(@RequestParam("E27")double E27,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE27(E27,caseId);
    }

    @RequestMapping(value="saveTheValueOfE29",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE29(@RequestParam("E29")double E29,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        sodaParameterService.saveTheValueOfE29(E29,caseId);
    }

    @RequestMapping(value="saveTheValueOfE30",method={RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE30(@RequestParam("E30")double E30,HttpSession session){
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        int powerId=Integer.parseInt(session.getAttribute("powerId").toString());
        sodaParameterService.saveTheValueOfE30(E30,caseId);

    }

    @RequestMapping(value = "calculateE6",method = RequestMethod.POST)
    @ResponseBody
    public double calculateE6(double E4, double E5,HttpSession session) {
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        double E6 = 0;
        try {
            E6 = DoubleUtil.getInstance().get3Double(enthalpyService.culB6(E4,E5 + Constant.KELVIN_TEMPERATURE));
        } catch (ParsingException e) {
            e.printStackTrace();
        } catch (EvalException e) {
            e.printStackTrace();
        }finally {
            sodaParameterService.saveTheValueOfE6(E6,caseId);
        }
        return E6;
    }

    @RequestMapping(value = "calculateE9",method = RequestMethod.POST)
    @ResponseBody
    public double calculateE9(double E7, double E8,HttpSession session) {
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        double E9 = 0;
        try {
            E9 = DoubleUtil.getInstance().get3Double(enthalpyService.culB6(E7, E8 + Constant.KELVIN_TEMPERATURE));
        } catch (ParsingException e) {
            e.printStackTrace();
        } catch (EvalException e) {
            e.printStackTrace();
        }finally {
            sodaParameterService.saveTheValueOfE9(E9, caseId);
        }
        return E9;
    }

    @RequestMapping(value = "calculateE12",method = RequestMethod.POST)
    @ResponseBody
    public double calculateE12(double E10, double E11,HttpSession session) {
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        double E12 = 0;
        try {
            E12 = DoubleUtil.getInstance().get3Double(enthalpyService.culB6(E10, E11 + Constant.KELVIN_TEMPERATURE));
        } catch (ParsingException e) {
            e.printStackTrace();
        } catch (EvalException e) {
            e.printStackTrace();
        }finally {
            sodaParameterService.saveTheValueOfE12(E12, caseId);
        }
        return E12;
    }

    @RequestMapping(value = "calculateE16",method = RequestMethod.POST)
    @ResponseBody
    public double calculateE16(double E14, double E15,HttpSession session) {
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        double E16 = 0;
        try {
            E16 = DoubleUtil.getInstance().get3Double(enthalpyService.culB6(E14, E15 + Constant.KELVIN_TEMPERATURE));
        } catch (ParsingException e) {
            e.printStackTrace();
        } catch (EvalException e) {
            e.printStackTrace();
        }finally {
            sodaParameterService.saveTheValueOfE16(E16, caseId);
        }
        return E16;
    }

    @RequestMapping(value = "calculateE19",method = RequestMethod.POST)
    @ResponseBody
    public double calculateE19(double E17, double E18,HttpSession session) {
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        double E19 = 0;
        try {
            E19 = DoubleUtil.getInstance().get3Double(enthalpyService.culB6(E17, E18 + Constant.KELVIN_TEMPERATURE));
        } catch (ParsingException e) {
            e.printStackTrace();
        } catch (EvalException e) {
            e.printStackTrace();
        }finally {
            sodaParameterService.saveTheValueOfE19(E19,caseId);
        }
        return E19;
    }

    @RequestMapping(value = "calculateE23",method = RequestMethod.POST)
    @ResponseBody
    public double calculateE23(double E21, double E22,HttpSession session) {
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        double E23 = 0;
        try {
            E23 = DoubleUtil.getInstance().get3Double(enthalpyService.culB6(E21, E22 + Constant.KELVIN_TEMPERATURE));
        } catch (ParsingException e) {
            e.printStackTrace();
        } catch (EvalException e) {
            e.printStackTrace();
        }finally {
            sodaParameterService.saveTheValueOfE23(E23, caseId);
        }
        return E23;
    }

    @RequestMapping(value = "calculateE27",method = RequestMethod.POST)
    @ResponseBody
    public double calculateE27(double E25, double E26,HttpSession session) {
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        double E27 = 0;
        try {
            E27 = DoubleUtil.getInstance().get3Double(enthalpyService.culB6(E25, E26 + Constant.KELVIN_TEMPERATURE));
        } catch (ParsingException e) {
            e.printStackTrace();
        } catch (EvalException e) {
            e.printStackTrace();
        }finally {
            sodaParameterService.saveTheValueOfE27(E27, caseId);
        }
        return E27;
    }

    @RequestMapping(value = "calculateE30",method = RequestMethod.POST)
    @ResponseBody
    public double calculateE30(double E3, double E29,HttpSession session) {
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        return sodaParameterService.calculateE30(E3, E29, caseId);
    }

    @RequestMapping(value = "sodaParameterSave", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResponse sodaParameterSave(SodaParameter sodaParameter) {
        try {
            sodaParameterService.sodaParameterSave(sodaParameter);
            return new AjaxResponse();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResponse(ReturnState.ERROR, "请检查填写数据是否有误，操作失败");
        }
    }
}
